#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;

struct Range{
	int l,r;
}a[N];

bool cmp(Range a,Range b){
	return a.l<b.l;
}

int main(){
	int n,st,ed;
	cin>>st>>ed>>n;
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		a[i]={l,r};
	}
	
	sort(a,a+n,cmp);
	
	int res=0;
	bool success=false;
	for(int i=0;i<n;i++){
		int j=i,r=-2e9;
		while(j<n&&a[j].l<=st){
			r=max(r,a[j].r );
			j++;
		}
		if(r<st){
			res=-1;
			break;
		}
		res++;
		if(r>=ed){
			success=true;
			break;
		}
		st=r;
		i=j-1;	
	} 
	
	if(!success) res=-1;
	cout<<res<<endl;
	
}
